# 查看目标值是否在列表内，查看目标值下标
# 有序序列

def erfen():
    list1 = [1,2,3,4,5,6,7,8]
    # 目标值
    number = 9
    # 左指针
    left = 0
    # 右指针
    right = len(list1)-1
    # 查找次数
    count = 0

    while left <= right:
        mid = (left + right) // 2
        count += 1
        if number < list1[mid]:
            right = mid - 1
        elif number > list1[mid]:
            left = mid + 1
        elif number == list1[mid]:
            print(f'目标值下标：{mid}')
            print(f"查找次数：{count}")
            break
    else:
        print("未找到目标值")

erfen()